# coding=utf-8
"""
    @project: qabot
    
    @file： team_serializers.py
    @date：2023/9/5 16:32
    @desc:
"""
import os
import json
from django.core import cache
from django.db.models import Q, QuerySet
from drf_yasg import openapi
from rest_framework import serializers
from common.util import common as util
from common.exception.app_exception import AppApiException

from common.mixins.api_mixin import ApiMixin
from django.utils.translation import gettext_lazy as _
from xpack.models import AuthConfig
from common.util.rsa_util import rsa_long_decrypt
user_cache = cache.caches['user_cache']

class LicenseSerializer(serializers.Serializer):
    class Query(ApiMixin, serializers.Serializer):
        def info(self, with_valid=True):
            if with_valid:
                super().is_valid(raise_exception=True)
            licensePath = os.environ.get("WLOU_LICENSE")
            content = ""
            if licensePath is not None:
                try:
                    with open(licensePath, 'r') as file:
                        content = file.read()
                except IOError:
                    print("授权文件错误")
            info = {
                'license': {
                    'corporation': '',
                    'expired': '',
                    'serialNo': '',
                    'remark': '',
                }
            }
            if content != "":
                info['license'] = json.loads(rsa_long_decrypt(content))
            return info
   
